package repositorios;

import interfaceRepositorio.IRepositorioSmnaPesquisa;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import excecoes.FalhaPersistenciaException;

public class RepositorioSmnaPesquisa extends RepositorioAbstrato implements IRepositorioSmnaPesquisa {

	private String consultaStm = "SELECT * FROM TBSemanaPesquisa";
	 
	
	public RepositorioSmnaPesquisa() {
		super();
	}			
	
	
	public Collection<String> consultar() throws FalhaPersistenciaException{
		Connection conn = encontrarConexao();
		PreparedStatement stm = null;
		ResultSet result = null;
		Collection<String> retorno = new ArrayList<String>();
		
		try {
			stm = conn.prepareStatement(consultaStm);
						
			result = stm.executeQuery();
			while(result.next()){
				retorno.add(result.getString("nome"));				
			}
		} catch (SQLException e) {
			throw new FalhaPersistenciaException("Erro na consulta da Semana da Pesquisa.");
		} finally{
			try {
				stm.close();
				if(result!=null){
					result.close();
				}
			} catch (SQLException e) {
				throw new FalhaPersistenciaException("Erro finalizando consulta da Semana da Pesquisa.");
			}
		}
		
		return retorno;
	}	
	
	
}
